<template>
  <div>
    <div class="row-header">
      <el-form :model="form" :rules="formRules" :inline="true" label-width="150px">
        <el-form-item label="通道选择">
          <el-select v-model="form.channelCompanyId" placeholder="通道选择" style="width: 300px;"
                     @change="getID">
            <el-option v-for="company in form.dictOperatorNameSelect" :key="company.id" :label="company.name"
                       :value="company.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="imsi" prop="imsi">
          <el-input v-model.trim="form.imsi" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="iccid" prop="iccid">
          <el-input v-model.trim="form.iccid" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="msisdn" prop="msisdn">
          <el-input v-model.trim="form.msisdn" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="启动时间">
          <el-date-picker class="select" v-model="form.queryDate" type="daterange" align="right" range-separator="至"
                          start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
      </el-form>
      <div class="row-form-btn">
        <el-button type="shenda" size="small" icon="el-icon-search" @click="currentPage = 1 ; initData()">
          查询
        </el-button>
      </div>
    </div>
    <div class="split-line"></div>
    <div class="row-main">
      <el-table :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" :data="tableData"
                tooltip-effect="dark"
                class="row-main-table" @selection-change="handleSelectionChange" v-loading.fullscreen="tableLoading"
                element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.2)">
        <el-table-column type="selection" align="center"></el-table-column>
        <el-table-column prop="imsi" label="imsi" align="center"></el-table-column>
        <el-table-column prop="msisdn" label="msisdn" align="center"></el-table-column>
        <el-table-column prop="iccid" label="iccid" align="center"></el-table-column>
        <el-table-column prop="dictChannelCompanyName" label="通道" align="center"></el-table-column>
        <el-table-column prop="dictIsSentName" label="是否执行" align="center"></el-table-column>
        <el-table-column prop="insertTime" label="创建时间" align="center"></el-table-column>
        <el-table-column prop="queryDate" label="启动时间" align="center"></el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" class="row-main-pager"
                     :current-page.sync="currentPage" :page-size="pageSize" layout="total,sizes,prev, pager, next, jumper"
                     :page-sizes="[10,20,50,100]" :total="total" background></el-pagination>
    </div>
  </div>
</template>

<script>
import {nextMonthStatus, interfaceAccountConfigurationSelect} from '@/api/getData'

export default {
  name: 'StatusChange',
  data() {
    const validateCardId = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('cardId不能超过50位'))
      } else {
        callback()
      }
    }
    const validateImsi = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('imsi不能超过50位'))
      } else {
        callback()
      }
    }
    const validateIccid = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('iccid不能超过50位'))
      } else {
        callback()
      }
    }
    const validateMsisdn = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('msisdn不能超过50位'))
      } else {
        callback()
      }
    }
    return {
      form: {
        cardId: '',
        imsi: '',
        iccid: '',
        msisdn: '',
        dictChannelCompany: '',
        dictChannelCompanyName: '',
        channelCompanyId: '',
        dictOperatorNameSelect: [],
        queryDate: ''
      },
      formRules: {
        cardId: [{validator: validateCardId, trigger: 'blur'}],
        imsi: [{validator: validateImsi, trigger: 'blur'}],
        iccid: [{validator: validateIccid, trigger: 'blur'}],
        msisdn: [{validator: validateMsisdn, trigger: 'blur'}],
      },
      maxPage: 1,
      tableData: [],
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableLoading: false,
      value: false,
      cardId: '',
      imsi: '',
      iccid: '',
      msisdn: '',
      customerId: '',
      ditcToStatus: '',
      dictIsSentName: '',
      insertTime: '',
      cUser: ''
    }
  },
  created() {
    this.initData()
  },
  methods: {
    async initData() {
      this.tableLoading = true;
      const returnData = await nextMonthStatus({
          cardId: this.form.cardId,
          imsi: this.form.imsi,
          iccid: this.form.iccid,
          msisdn: this.form.msisdn,
          customerId: this.customerId,
          dictChannelCompany: this.form.dictChannelCompany,
          queryDate: this.form.queryDate,
          page: {
            current: this.currentPage + '',
            size: this.pageSize + '',
            ascs: this.ascs,
            descs: this.descs
          }
        },
        {
          obj: this,
          key: 'tableLoading'
        })
      this.tableData = [];
      this.total = 0;
      if (returnData._result) {
        this.maxPage = Math.ceil(returnData.data.total / this.pageSize) // 分页的最大页数
        returnData.data.records.map(item => {
          const obj = {}
          obj.cardId = item.cardId // cardId
          obj.imsi = item.imsi // imsi
          obj.iccid = item.iccid // iccid
          obj.msisdn = item.msisdn // msisdn
          obj.ditcToStatus = item.ditcToStatus // 去更改状态
          obj.dictIsSentName = item.dictIsSentName // 是否执行
          obj.insertTime = item.insertTime // 创建时间
          obj.customerId = item.customerId // 用户名称
          obj.cUser = item.cUser // 用户名称
          if (item.dictChannelCompany === 'TELECOM') {
            obj.dictChannelCompanyName = '电信'
          }
          if (item.dictChannelCompany === 'UNICOM') {
            obj.dictChannelCompanyName = '联通'
          }
          if (item.dictChannelCompany === 'JIUTIAN') {
            obj.dictChannelCompanyName = '九天'
          }
          if (item.dictChannelCompany === 'JIUTIAN_IOT') {
            obj.dictChannelCompanyName = '新九天IOT'
          }
          if (item.dictChannelCompany === 'KAHAO') {
            obj.dictChannelCompanyName = '业务号码'
          }
          this.tableData.push(obj)
        })
        this.total = returnData.data.total;
        this.tableLoading = false
      }

      const returnData1 = await interfaceAccountConfigurationSelect({})
      if (returnData1._result) {
        this.form.dictOperatorNameSelect = returnData1.data.map(item => {
          return {id: item.id, name: item.dictOperatorName, dictOperator: item.dictOperator}
        })
      }

    },
    getID() {
      this.form.dictOperatorNameSelect.forEach(item => {
        if (this.form.channelCompanyId === item.id) {
          this.form.dictChannelCompany = item.dictOperator
        }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.initData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.initData()
    },
  }
}
</script>

<style scoped lang="scss">

.examine /deep/ .el-dialog__body {
  text-align: center;
  font-size: 14px;
  font-family: 微软雅黑;
  line-height: 40px;
  color: #606266;
  font-weight: 700;
}

.el-popper[x-placement^=bottom] {
  margin-right: -25px;
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;

  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}

.el-popper[x-placement^=top] {
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;
  margin-right: -25px;

  button {
    display: block;
  }

  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}

.select /deep/ .el-range-separator {
  width: 15%;
}
</style>
